home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / CHASSIS_ / PRINTWIN.C < prev    next >
Text File  |  1992-05-14  |  4KB  |  114 lines

  1. /************************************************************************************/
  2. /*    PrintWindowProc                                                                    */
  3. /************************************************************************************/
  4.  
  5. #include "MyHeaders.h"
  6.  
  7. int PrintWindowProc(int Which)
  8. {
  9.     int            PrintWindRetCode = 0;
  10.     TEHandle    myPrTEH;
  11.     int            outHeight, outLines, outVert, outScroll;
  12.     long        outPageNo;
  13.     
  14.     Rect        IRect;
  15.     Handle        IHandle;
  16.     
  17.     Rect        dlogRect;
  18.     int            rectHeight, rectWidth;
  19.     int            newH, newV;
  20.     
  21.  
  22.     switch (windTbl[Which].windRec.refCon)        /* Get calling procedure info from    */
  23.         {                                        /* the window table                    */
  24.  
  25.         case (ProcText):                                /* text window procedure    */
  26.             GetPort(&workGrafPtr);                            /* save GrafPort ptr    */
  27.             
  28.             CursorSelect(NIL, NIL, watchCursor);            /* set the cursor        */
  29.             
  30.                                                         /* get "Printing" dialog    */
  31.             myDlogPtr = GetNewDialog (141, NIL, (WindowPtr) -1);
  32.             dlogRect = (*myDlogPtr).portRect;                    /* position on d/t    */
  33.             rectHeight = dlogRect.bottom - dlogRect.top;        
  34.             rectWidth = dlogRect.right - dlogRect.left;
  35.             newH = (screenBits.bounds.right - rectWidth) * .50;    /* centered    horiz.    */
  36.             if (newH < 10)                                        /* not less than 10 */
  37.                 newH = 10;
  38.             newV = ((screenBits.bounds.bottom - 30                /* vert position    */
  39.                      - rectHeight)* (.33)) + 30;                /*   one-third down    */
  40.             if (newV < 30)                                        /* not less than 30    */
  41.                 newV = 30;
  42.             MoveWindow (myDlogPtr, newH, newV, TRUE);            /* move to position    */
  43.             ShowWindow (myDlogPtr);                                /* make visible        */
  44.             
  45.             (**prRecHdl).prJob.pIdleProc= (ProcPtr) myIdleProc;    /* install idleproc    */
  46.             
  47.             PrOpenDoc(prRecHdl,prPortPtr,NIL);                /* open the document    */
  48.                 
  49.             destRect = (**prRecHdl).prInfo.rPage;            /* printed page size    */
  50.             destRect.top += 42;                                /* lower top for icon    */
  51.             InsetRect (&destRect, 30,30);                    /* dest rect is smaller    */
  52.             
  53.                                             /* compute page scroll amount            */
  54.                                             /* and recompute rect sizes.            */
  55.                                             /* destRect a multiple of lineHeight    */
  56.             outHeight = (**windTbl[Which].windTEH[0]).lineHeight;
  57.             outVert = destRect.bottom - destRect.top;
  58.             outScroll = (outVert / outHeight ) * outHeight;
  59.             destRect.bottom = destRect.top + outScroll;
  60.             
  61.             viewRect = destRect;                        /* viewRect coincides        */
  62.  
  63.             myPrTEH = TENew(&destRect,&viewRect);        /* get TE area for output    */
  64.             
  65.                                                         /* copy font info to output    */
  66.             (**myPrTEH).txFont = (**windTbl[Which].windTEH[0]).txFont;
  67.             (**myPrTEH).txFace = (**windTbl[Which].windTEH[0]).txFace;
  68.             (**myPrTEH).txSize = (**windTbl[Which].windTEH[0]).txSize;
  69.             
  70.                                                             /* point to text        */
  71.             (**myPrTEH).hText = (**windTbl[Which].windTEH[0]).hText;
  72.             
  73.             TECalText(myPrTEH);                                /* reset line begins    */
  74.             
  75.             outPageNo = 0;                                    /* initialize page no    */
  76.             outLines = (**myPrTEH).nLines;                    /* initial # of lines    */
  77.             while ((outLines > 0) && (PrError() == 0))
  78.                 {
  79.                 PrOpenPage (prPortPtr, NIL);                /* open the page        */
  80.  
  81.                             /****************************************/
  82.                             /*    Draw the icon, or do any other        */
  83.                             /*    graphic or text drawing you want.    */
  84.                             /****************************************/
  85.                 SetRect (&IRect, 0,0, 32,32);                /* draw the icon        */
  86.                 UseResFile (myResRefNum);
  87.                 IHandle = GetResource ('ICN#', 128);
  88.                 PlotIcon (&IRect, IHandle);
  89.  
  90.  
  91.                 TEUpdate(&viewRect, myPrTEH);                /* draw the text        */
  92.  
  93.                 TEScroll(0, -outScroll, myPrTEH);            /* scroll the text        */
  94.                 outLines -= outScroll/outHeight;            /* new # of lines left    */
  95.                 PrClosePage (prPortPtr);                    /* close the page        */
  96.                 }
  97.                 
  98.             PrCloseDoc(prPortPtr);                            /* close the document    */
  99.  
  100.             SetPort(workGrafPtr);                            /* restore graf ptr        */
  101.  
  102.             if (((**prRecHdl).prJob.bJDocLoop==bSpoolLoop)        /* if batch            */
  103.                     && (PrError() == 0))
  104.                 {
  105.                 UseResFile (initResRefNum);                        /* for H/P printer    */
  106.                 PrPicFile (prRecHdl,prPortPtr,NIL,NIL,NIL);        /* print the spool    */
  107.                 }
  108.  
  109.             DisposDialog(myDlogPtr);                        /* get rid of dlog box    */
  110.         break;
  111.         }
  112.  
  113.     return PrintWindRetCode;
  114. }